﻿ 
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Configs</title>
    <link rel="stylesheet" href="~/lib/layui/css/layui.css">
    <script type="text/javascript" src="/win10/js/jquery-2.2.4.min.js"></script>
    <script type="text/javascript" src="~/lib/layui/layui.js"></script>
</head>
<body>
    <table class="layui-hide" id="tabledata" lay-filter="tabledata"></table>
    <script type="text/html" id="operation">
        <a class="layui-btn layui-btn-xs" lay-event="addDemand">添加需求</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="lookDemand">查看需求</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script>
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#tabledata'
                , height: 'full-20'
                , url: '/home/GetConfigsIteams'
                , toolbar: '#toolbarDemo'
                , title: '项目信息'
                , cols: [[
                    { type: 'checkbox', fixed: 'left' }
                    , { field: 'itemName', title: '项目名称', fixed: 'left', unresize: false, sort: true }
                    , { field: 'fileName', title: '文件名' }
                    , { field: 'version', title: '版本', sort: true }
                    , { field: 'env', title: '环境', sort: true }
                    , { field: 'keyName', title: '配置键', sort: true }
                    , { field: 'content', title: '配置值', sort: true }
                    , { field: '', title: '操作', fixed: 'right', templet: '#operation' }
                ]]
                , limits: [10, 20, 40, 60, 80, 100]
                , limit: 20 //默认采用10
                , page: true
                , request: {
                    pageName: 'pageNumber' //页码的参数名称，默认：page
                    , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
            });

            //监听工具条
            table.on('tool(tabledata)', function (obj) {
                var data = obj.data;
                if (obj.event === 'addDemand') {
                    x_admin_show("添加需求", "/project/ProjectDemand/add?Id=" + data.id, 777, 600);
                }
            });


            //头工具栏事件
            table.on('toolbar(tabledata)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
                    case 'add':
                        x_admin_show("添加项目", "/project/project/add", 777, 500);
                        break;
                    case 'update':
                        var data = checkStatus.data;
                        if (data.length > 1) {
                            layer.msg('请选择单个编辑项');
                            break;
                        }
                        else {
                            var thisline = data[0];
                            var id = thisline.id;
                            x_admin_show("更新项目信息", "/project/project/update?Id=" + id, 777, 500);
                        }
                        break;
                    case 'delete':
                        var data = checkStatus.data;
                        if (data.length > 1) {
                            layer.msg('请选择删除的项目');
                            break;
                        }
                        else {
                            var ids = [];
                            for (var i = 0; i < data.length; i++) {
                                ids.push(data[i].id);
                            }
                            BaseAjax(ajaxType.post, "/project/project/delete", { ids: ids }, function (repo) {
                                if (repo.status == ajaxStatus.OK) {
                                    table.reload('tabledata', { page: { curr: 1 } });
                                }
                            });
                        }
                        break;
                    case 'isAll':
                        layer.msg(checkStatus.isAll ? '全选' : '未全选');
                        break;
                };
            });
        });
    </script>
</body>
</html>
